<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="engineer.clientapp.beans.User" %>
   <%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="engineer.clientapp.tools.Connector" %>

<%
User user=(User)session.getAttribute("user");

%>
<script type="text/javascript" src="js/raports.js"></script>
<%if (session.getAttribute("user") == null) {%>
<h1>Brak dostępu do tej strony!</h1>
<%}else{ 
int id=user.getId();
String userID=String.valueOf(id);
Connection connection = new Connector().getConnection();
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("SELECT * FROM automats.machines");%>
<h2>Wygeneruj Raporty</h2>
<input type="hidden" value="<%=userID%>" id="userID" name="userID" />
<table style="width: 700px; height: 400px;">
<tr>
<td style="width: 200px; height: 40px; text-align: center;"><b>Nazwa</b></td>
<td style="width: 150px; height: 40px; text-align: center;"><b>Działanie</b></td>
<td style="width: 150px; height: 40px; text-align: center;"><b>Data wygenerowania</b></td>
<td style="width: 150px; height: 40px; text-align: center;"><b>Informacje</b></td>
</tr>
<tr>

<td><h4>Raport dotyczący stanu wszystkich automatów</h4></td>
<td style="width: 150px; height: 40px; text-align: center;"><input type='submit' id='generateAll' class='styled-button-12' value='Wygeneruj Raport' /><br/>
<input type='submit' class='styled-button-12' id='readAll' value='Odczytaj Raport' /></td>
<td style="width: 150px; height: 40px; text-align: center;"><div id="creationDateAll" ></div></td>
<td style="width: 150px; height: 40px; text-align: center;"><div id="info">Brak</div></td>
</tr>



<tr>
<td><h4>Raport dotyczący braków w automatach</h4></td>
<td style="width: 150px; height: 40px; text-align: center;"><input type='submit' id='generateEmpty' class='styled-button-12' value='Wygeneruj Raport' /><br/>
<input type='submit' class='styled-button-12' value='Odczytaj Raport' id='readEmpty' /></td>
<td style="width: 150px; height: 40px; text-align: center;"><div id="creationDateEmpties"></div></td>
<td style="width: 150px; height: 40px; text-align: center;"><div id="info2">Brak</div></td>
</tr>

<tr>
<td><h4>Raport dotyczący stanu w wybranym automacie:</h4>
<div class="styled-select-2">
<select name="machineID" id="machineID">
<option value="0">Wybierz... </option>
<%
while(result.next()){%>
<option value="<%=result.getString("id") %>"><%=result.getString("name") %></option>
<% 
} %>
</select>
</div>
</td>
<td style="width: 150px; height: 40px; text-align: center;"><input type='submit' id='generateSelected' class='styled-button-12' value='Wygeneruj Raport' /><br/>
<input type='submit' class='styled-button-12' value='Odczytaj Raport' id='readSelected' /></td>
<td style="width: 150px; height: 40px; text-align: center;"><div id="creationDateSelected"></div></td>
<td style="width: 150px; height: 40px; text-align: center;"><div id="info3">Brak</div></td>
</tr>
</table>

<script type="text/javascript">
	var reportMaster = new Report();
	reportMaster.getCreationDate('all');
	reportMaster.getCreationDate('empty');
	reportMaster.getCreationDate('selected');
	 $('#generateAll').live('click', function(){new Report().sendToAll('all');});
	 $('#generateEmpty').live('click', function(){new Report().sendToEmpties('empty');});
	 $('#generateSelected').live('click', function(){new Report().sendToSelected('selected');});
	 $('#readAll').live('click', function(){new Report().readPDF('all');});
	 $('#readEmpty').live('click', function(){new Report().readPDF('empty');});
	 $('#readSelected').live('click', function(){new Report().readPDF('selected');});
</script>

<%}%>